<?php

class XQL_Simple_QuerySet extends XQL_QuerySet
{
	/**
	 * A lekéréshez rendelt adatbázis tábla.
	 * @var XQL_Table
	 */
	protected $table;

	/**
	 * Bizonyos lekérésekhez használatos, a tábla kulcsmezőit tartalmazza.
	 * @var array
	 */
	protected $keys = array();

	public function __construct($preset='default')
	{
		parent::__construct($preset);

		$this->queries['get'] = XQL_Simple_GetQuery::create('simple', $preset);
		$this->queries['getList'] = XQL_Simple_GetListQuery::create('simple', $preset);
		$this->queries['countList'] = XQL_Simple_CountListQuery::create('simple', $preset);
		$this->queries['add'] = XQL_Simple_InsertQuery::create('simple', $preset);
		$this->queries['modify'] = XQL_Simple_UpdateQuery::create('simple', $preset);
		$this->queries['remove'] = XQL_Simple_DeleteQuery::create('simple', $preset);
	}

	/**
	 *
	 * @param XQL_Table $table
	 * @return XQL_Simple_QuerySet
	 */
	protected function setTable(XQL_Table $table)
	{
		$this->table = $table;
		return $this;
	}

	/**
	 *
	 * @param XQL_Field $keyField
	 * @return XQL_Simple_QuerySet
	 */
	protected function addKey(XQL_Field $keyField)
	{
		$this->keys[] = $keyField;
		return $this;
	}

	/**
	 *
	 * @return XQL_Simple_QuerySet
	 */
	protected function setupQueries()
	{
		foreach ($this->queries as $name=>$query)
		{
			$query->setup($this->table, $this->keys);
		}
		return $this;
	}
}
?>